//
//  TGMTableMoreCell.m
//  TravelGuideMdd
//
//  Created by Song Xiaofeng on 13-6-21.
//  Copyright (c) 2013年 mafengwo.com. All rights reserved.
//

#import "TGMTableMoreCell.h"
#import "TGMActivityIndicatorView.h"

@implementation TGMTableMoreCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        _infoLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 13, self.contentView.boundsWidth, 14)];
        _infoLabel.font = [UIFont systemFontOfSize:13];
        _infoLabel.backgroundColor = [UIColor clearColor];
        _infoLabel.textAlignment = NSTextAlignmentCenter;
        _infoLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
        _infoLabel.textColor = [UIColor colorWithRed:120.0/255.0 green:120.0/255.0 blue:120.0/255.0 alpha:1.0];
        [self.contentView addSubview:_infoLabel];
        
        _activityIndicatorView = [TGMActivityIndicatorView defaultActivityIndicatorView];
        _activityIndicatorView.color = C_RGB(0xfa9f00);
        _activityIndicatorView.hidesWhenStopped = YES;
        _activityIndicatorView.hidden = YES;
        [self.contentView addSubview:_activityIndicatorView];
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

- (void)layoutSubviews
{
    CGFloat centerX = self.frame.size.width * 0.5;
    CGFloat centerY = self.frame.size.height * 0.5;
    
    _infoLabel.centerX = centerX;
    _activityIndicatorView.center = CGPointMake(centerX, centerY);
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setInfoText:(NSString*)infoString forState:(MoreCellState)state;
{
    _state = state;
    if (_state == MoreCellState_Loading)
    {
        _activityIndicatorView.hidden = NO;
        [_activityIndicatorView startAnimating];
        _infoLabel.hidden = YES;
        
//        _infoLabel.frame = CGRectMake(_activityIndicatorView.frameX + _activityIndicatorView.frameWidth + 5, 15, 200, 15);
    }
    else
    {
        [_activityIndicatorView stopAnimating];
        _infoLabel.hidden = NO;
        _infoLabel.text = infoString;
        
    }
}
@end
